package util.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DemoDataListener extends AnalysisEventListener<BasePurchaseExecutionResponse> {
    private static final Logger LOGGER = LoggerFactory.getLogger(DemoDataListener.class);
    @Override
    public void invoke(BasePurchaseExecutionResponse basePurchaseExecutionResponse, AnalysisContext analysisContext) {

        LOGGER.info("解析到一条数据:{}", JSON.toJSONString(basePurchaseExecutionResponse));
//        list.add(data);
        // 达到BATCH_COUNT了，需要去存储一次数据库，防止数据几万条数据在内存，容易OOM
//        if (list.size() >= BATCH_COUNT) {
//            saveData();
//            // 存储完成清理 list
//            list.clear();
//        }

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        LOGGER.info("所有数据解析完成！");
    }
}
